package com.mq.ps.direct;

import com.mq.config.ConnectUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeoutException;

/**
 * @author hezhaoxiang
 * @Deprecated //订阅模型 direct 生产者
 * @date 16:27 2020/9/6
 **/
/**
 * @author hezhaoxiang
 * @Deprecated // 订阅模型 direct 生产者
 * @date 19:42 2020/9/7
 **/
public class HelloWorldSend {

    //路由名称
    private final static String EXCHANGE_NAME = "PS_DIRECT_EXCHANGE";

    private static void sendMsg() throws URISyntaxException, KeyManagementException, TimeoutException, NoSuchAlgorithmException, IOException {
        //1. 获取连接
        Connection connect = ConnectUtils.getConnect();
        //2. 创建信道
        Channel channel = connect.createChannel();
        //3. 声明路由， 路由名称 EXCHANGE_NAME ,模型 fanout
        channel.exchangeDeclare(EXCHANGE_NAME,"direct");
        //4. 发送消息
        String msg = "修改一条消息";
        channel.basicPublish(EXCHANGE_NAME, "UPDATE", MessageProperties.TEXT_PLAIN, msg.getBytes());
        System.out.println("direct 模型 成功发送消息:" + msg);
        //5. 关闭信道
        channel.close();
        //6. 关闭连接
        connect.close();
    }

    public static void main(String[] args) throws KeyManagementException, TimeoutException, NoSuchAlgorithmException, IOException, URISyntaxException {
        HelloWorldSend.sendMsg();
    }
}
